package com.yuwei.module_vehicles.vm

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.vm.BaseViewModel2
import com.bw.lib_http.entity.*
import com.yuwei.module_vehicles.model.VehiclesRepository
import kotlinx.coroutines.launch

class VehiclesViewModel:BaseViewModel2<VehiclesRepository>() {
    val getCarPaymentsSuccess by lazy { MutableLiveData<CarPaymentsEntity>() }
    fun getCarPayments(){
        mViewModelScope.launch (mDispatcher){
            val result = mRepository.getCarPayments()
            if (result.code == 200){
                getCarPaymentsSuccess.postValue(result.data)
            }
        }
    }
    //省份简码
    val getCarProvincesSuccess by lazy { MutableLiveData<ProvincesEntity>() }
    fun getProvinces(){
        mViewModelScope.launch {
            val result = mRepository.getProvinces()
            if (result.code == 200){
                getCarProvincesSuccess.postValue(result.data)
            }
        }
    }
    val getAddCarSuccess by lazy { MutableLiveData<VehiclesEntity>() }
    fun getAddCar(vehiclesBody: VehiclesBody){
        mViewModelScope.launch {
            val result = mRepository.getVehicles(vehiclesBody)
            if (result.code == 200){
                getAddCarSuccess.postValue(result.data)
            }
        }
    }
    val getDeleteCarSuccess by lazy { MutableLiveData<String>() }
    fun deleteCar(id:Int){
        mViewModelScope.launch {
            val result = mRepository.getDeleteCar(id)
            if (result.code == 200){
                getDeleteCarSuccess.postValue(result.data)
            }
        }
    }
    //缴费
    val getAddPaymentsSuccess by lazy { MutableLiveData<AddPaymentsEntity>() }
    fun getAddPayments(addPaymentsBody: AddPaymentsBody){
        mViewModelScope.launch {
            val result = mRepository.getAddPayments(addPaymentsBody)
            if (result.code == 200){
                getAddPaymentsSuccess.postValue(result.data)
            }
        }
    }
    override fun createRepository() = VehiclesRepository()
}